<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%@ page isELIgnored="false"%>
<% 
Object completeUrlObj = request.getAttribute("completeUrl"); 
Object fln_UserCodeObj = request.getAttribute("fln_UserCode"); 
String completeUrl = "";
if(completeUrlObj!=null){
	completeUrl = completeUrlObj.toString().trim();
}
String fln_UserCode = "";
if(fln_UserCodeObj!=null){
	fln_UserCode = fln_UserCodeObj.toString().trim();
}
%>
<script type="text/javascript" charset="utf-8">
	var jsonObj2 ='';
	var selected2 = [];//已选择的
	var templateNode_ID ='';
	var fln_UserCode = '<%=fln_UserCode%>';
	var ftn_UserNum = 0;
	var fln_data; 
	var ftn_Class;
	function loadNextflowTemplateNode(){
		var combobox100 = $('#templateNode_ID').combobox({//加载下拉菜单
			url : 'flowTemplateNodeAction!backFlowTemplateNode.action?lineStart='+$('#lineStart').val()+'&ftn_ID='+$('#ftn_ID').val()+'&xiangMuJBXXBH=${xiangMuJBXXBH}&ftc_ID=${ftc_ID}',
			valueField : 'ftn_ID',
			textField : 'ftn_Name',
			editable : false,
			panelHeight : 'auto',
			onLoadSuccess : function(data) {//加载完成之后关闭 正在加载提示
				fln_data =data;
				try{
					var flowTemplateNodes100 = combobox100.combobox('getData');
					if(flowTemplateNodes100.length>0){
						combobox100.combobox('select',flowTemplateNodes100[0].ftn_ID);
					}
				}catch(e){}
			},onChange:function(newValue,oldValue){
				try{
					if(fln_data!=undefined){
						for(var i=0;i<fln_data.length;i++){
							if(fln_data[i].ftn_ID==newValue){
								ftn_UserNum	= fln_data[i].ftn_UserNum;
								ftn_Class = fln_data[i].ftn_Class;
								break;
							}
						}
					}
					templateNode_ID = newValue;
					loadUser($('#userName').val());
				}catch(e){}
			}
		});		
	}
	loadNextflowTemplateNode();

	function loadUser(userName){
		jsonObj2 = '';
		selected2 = [];
		$("#select3").empty();
		$("#selected3").empty();
		if(userName==undefined||userName==''||userName==null){
			userName = '';
		}
		$.ajax({
			url:'flowTemplateNodeAction!backUpCandidate.action',
			data:'templateNode_ID='+templateNode_ID+'&fln_UserCode='+fln_UserCode+'&ftn_ID='+$('#ftn_ID').val()+'&conditionUserName='+userName+'&xiangMuJBXXBH=${xiangMuJBXXBH}',
			success : function(jsonStr) {
				jsonObj2 = $.parseJSON(jsonStr);
				if(ftn_Class!=undefined&&ftn_Class<0){
					var num = 0;
					for(var i=0;i<jsonObj2.length;i++){
						$("<option value='"+jsonObj2[i].userID+"'>"+jsonObj2[i].userName+"</option>").appendTo("#selected3");//添加下拉框的option
						selected2.push(jsonObj2[i].userID);
						num++;
					}
					ftn_UserNum =num;
				}else{
					for(var i=0;i<jsonObj2.length;i++){
						$("<option value='"+jsonObj2[i].userID+"'>"+jsonObj2[i].userName+"</option>").appendTo("#select3");//添加下拉框的option
					}
				}
			}
		});
	}

	/**
	* 提交查询
	**/
	function _search() {
		loadUser($('#userName').val());
	}
	
	function select2(){
		var temp = $("#select3").val();
		if(ftn_UserNum!=undefined&&ftn_UserNum!=0){//如果有设置人数
			try{
			var totle =0;
			if(selected2!=undefined) totle += selected2.length;
			if(temp!=undefined) totle += temp.length;
			if(totle>ftn_UserNum){
				parent.dagong.messagerAlert('<s:text name="prompt"></s:text>','该任务只允许分派给'+ftn_UserNum+'个以内人员办理');
				return;
			}
			}catch(e){}
		}

		for(var x=0;x<temp.length;x++){
			selected2.push(temp[x]);	
		}
		fill();
	}
	
	function cancelSelected2(){
		var temp = $("#selected3").val();
		var tempArr = [];
		for(var x=0;x<selected2.length;x++){
			var a = 0;
			for(var i=0;i<temp.length;i++){
				if(temp[i]==selected2[x]){
					a = 1;
					break;
				}
			}
			if(a == 0){
				tempArr.push(selected2[x]);
			}
		}
		selected2 = tempArr;
		fill();
	}
	
	function fill(){
		$("#select3").empty();
		$("#selected3").empty();
		for(var i=0;i<jsonObj2.length;i++){
			var userID =jsonObj2[i].userID; 
			var userName =jsonObj2[i].userName; 
			var a = 0;
			for(var x=0;x<selected2.length;x++){
				if(selected2[x]==userID){
					$("<option value='"+userID+"'>"+userName+"</option>").appendTo("#selected3");
					a = 1;
					break;
				}
			}
			if(a == 0){
				$("<option value='"+userID+"'>"+userName+"</option>").appendTo("#select3");
			}
		}
	}
	function next2(){
		if(selected2==undefined||selected2==''){parent.dagong.messagerAlert('<s:text name="prompt"></s:text>','请选择任务处理人！');return false;}
		
		var completeUrl = '<%=completeUrl%>';
		var ff =null;
		if(completeUrl==''||completeUrl==undefined){
			completeUrl = 'renWuJBXXAction!next.action?1=1';
		}else{
			ff = share.data('tongguoform');
		}
		if(ff!=null){ 
			ff.append('<textarea name="handlePrompt" style="display: none">'+$('#handlePrompt').val()+'</textarea>');
			//alert(completeUrl+'&templateNode_ID='+templateNode_ID+'&ftn_ID='+$('#ftn_ID').val()+'&fln_UserCode='+selected2);
			ff.form('submit',{
				url:completeUrl+'&templateNode_ID='+templateNode_ID+'&ftn_ID='+$('#ftn_ID').val()+'&fln_UserCode='+selected2,//流程实例id 、任务id、 被选人 
				success : function(jsonStr) {
					var win = share.data('win');//提示的位置
					var json = $.parseJSON(jsonStr);
					try{
						showMessage(json,win);//tishi
					}catch(e){}
					
					if (json.success) {
						var pnd = share.data('processNextDialog');	
						try{
							pnd.dialog('close');
							share.removeData('processNextDialog');
							share.removeData('tongguoform');
							share.removeData('win');		
						}catch(e){
						}
						try{
							closePage();//上一个页面的方法
						}catch(e){
						}
						
	
						var datagrid = share.data('datagrid');//如果上一个页面不是表单
						try{
							datagrid.datagrid('reload');
						}catch(e){
						}
						share.data('success',true);
					}
				}
			});
		}
	}
	


</script>
	
<div align="center" style="overflow: hidden;padding: 10px;">
		<input id="ftn_ID" name="ftn_ID" type="hidden" value="<s:property value="flowTemplateNode.ftn_ID"/>" />
		<input id="lineStart" name="lineStart" type="hidden" value='<s:property value="flowTemplateNode.lineStart"/>'/>
		<table cellSpacing=0 cellPadding=0 width="100%" style="background:#f9f9f9">
			<tr style="height:28px" >
				<td align="left" style="padding-left: 15px;">退回到：</td>
				<td colspan="2" align="left" ><input id="templateNode_ID" name="ftn_ID" style="width:220px;"/></td>
			</tr>
			<tr style="height:28px" >
				<td align="left" style="padding-left: 15px;" colspan="3">提交给：</td>
			</tr>
		</table>
		<table cellSpacing=0 cellPadding=0 width="100%" style="background:#f9f9f9">
			<tr>
				<td style="padding-left: 15px;">
					<select  style="width:165px;height:230px;" id="select3" multiple="multiple"></select>
				</td>
				<td width="30px">
					<a href="javascript:void(0);"class="easyui-linkbutton" onclick="select2();">></a>
					<div >&nbsp;</div>
					<a href="javascript:void(0);"class="easyui-linkbutton" onclick="cancelSelected2();"><</a>
				</td>
				<td style="padding-right: 15px;">
					<select  style="width:165px;height:230px;" id="selected3" name="nextParticipants" multiple="multiple"></select>
				</td>
			</tr>
			<tr style="height: 28px" ><td style="padding-left: 15px;" colspan="3" align="left">办理提示：</td></tr>
			<tr>
				<td style="padding-left: 15px;padding-right: 15px;" colspan="3">
					<textarea class="textarea" id="handlePrompt" rows="6" style="width: 100%;float:left;border:1px #d3d3d3 solid; width:99%; line-height:20px;"></textarea>
				</td>
			</tr>
			<tr style="height: 38px">
				<td style="padding-left: 15px;padding-right: 15px;" colspan="3" align="right">
					<a href="javascript:void(0);" class="easyui-linkbutton" onclick="next2();">确定</a>
				</td>
			</tr>
		</table>

</div>